/*
  This file is part of JCM.

  JCM is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  JCM is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with JCM.  If not, see <http://www.gnu.org/licenses/>.
*/
import java.awt.*;
import javax.swing.*;

/** Renderizador de itens de listas com margens horizontais. */
public class ComboCellRenderer extends DefaultListCellRenderer
{
  /** Construtor da classe extendida. */
  public ComboCellRenderer()
  {
    super();
  }

  /**
   * Método objeto da extensão incrementando a área de renderização para
   * que haja margens horizontais entre o conteúdo e as bordas.
   *
   * @param insets O insets do super componente.
   * @return Insets do super componente incrementado de margens.
  */
  @Override public Insets getInsets(Insets insets)
  {
    Insets i = super.getInsets(insets);
    FontMetrics metric = getFontMetrics(UIManager.getFont("Panel.font"));
    int margin = (2 * metric.charWidth('M')) / 5; // CSS 0.4em
    i.left += margin;
    i.right += margin;
    return i;
  }

  static final long serialVersionUID = -8714038156164748665L;
}
